#============================================================
#	Card Item
#============================================================
#  卡片节点
#============================================================
# @datetime: 2022-5-4 19:50:49
#============================================================
class_name CardItem
extends MarginContainer


onready var _icon : TextureRect = get_node("Icon")
# 用于将 TextureRect 节点添加到这个节点上
onready var _anim_control : Control = get_node("AnimControl")
onready var _tween : Tween = get_node("Tween")


var _duration : float = 0.0
var _trans_type : int = 0
var _ease_type : int = 2


#============================================================
#   Set/Get
#============================================================
func get_icon_node() -> TextureRect:
	return _icon as TextureRect

func get_card_position() -> Vector2:
	return _icon.rect_position

func set_duration(value: float) -> CardItem:
	_duration = value
	return self

func set_trans_type(value) -> CardItem:
	_trans_type = value
	return self

func set_ease_type(value) -> CardItem:
	_ease_type = value
	return self

func set_card_position(value: Vector2, global: bool = false):
	if not global:
		get_icon_node().rect_position = value
	else:
		get_icon_node().rect_global_position = value

func add_card_position(value: Vector2):
	get_icon_node().rect_position += value


#============================================================
#   内置
#============================================================
func _ready():
	var pos = _icon.rect_position
	remove_child(_icon)
	_anim_control.add_child(_icon)
	_icon.rect_position = pos
	_icon.set_margins_preset(Control.PRESET_WIDE)


#============================================================
#   自定义
#============================================================
##  移动到
## @from  
## @to  
## @return  
func move_to(
	from : Vector2, 
	to: Vector2 = Vector2.INF
) -> CardItem:
	if to == Vector2.INF:
		to = from
		from = _icon.rect_position
	_tween.interpolate_property(
		_icon, "rect_position",
		from, to,
		_duration, _trans_type, _ease_type
	)
	_tween.start()
	return self


## 渐隐/渐出
func fade(from: float, to: float) -> CardItem:
	_tween.interpolate_property(
		_icon, "modulate:a",
		from, to, _duration, _trans_type, _ease_type
	)
	_tween.start()
	return self


##  调用对象的方法，传入数值
## @object  
## @method  
func interpolate_method(object: Object, method: String):
	_tween.interpolate_method(
		object, method, 
		0.0, 1.0,
		_duration, _trans_type, _ease_type
	)
	_tween.start()




